package org.jeecg.modules.xmss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.xmss.entity.XmssTowns;
import org.jeecg.modules.xmss.mapper.XmssTownsMapper;
import org.jeecg.modules.xmss.service.IXmssTownsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;

/**
 * @Description: 乡镇信息表-公众号标识
 * @Author: jeecg-boot
 * @Date:   2020-09-18
 * @Version: V1.0
 */
@Service
public class XmssTownsServiceImpl extends ServiceImpl<XmssTownsMapper, XmssTowns> implements IXmssTownsService {

	@Autowired
	private XmssTownsMapper xmssTownsMapper;

	@Override
	@Transactional
	public void saveMain(XmssTowns xmssTowns) {
		xmssTownsMapper.insert(xmssTowns);
	}

	@Override
	@Transactional
	public void updateMain(XmssTowns xmssTowns) {
		xmssTownsMapper.updateById(xmssTowns);

		//1.先删除子表数据

		//2.子表数据重新插入
	}

	@Override
	@Transactional
	public void delMain(String id) {
		xmssTownsMapper.deleteById(id);
	}

	@Override
	@Transactional
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			xmssTownsMapper.deleteById(id);
		}
	}

	@Override
	public XmssTowns selectTownsByPublicOpenId(String publicOpenId) {
		LambdaQueryWrapper<XmssTowns> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(XmssTowns::getOpenId, publicOpenId);
		XmssTowns xmssTowns = baseMapper.selectOne(queryWrapper);
		return xmssTowns;
	}

}
